from flask_restful import Resource

from model.crud import QueryOneInstance
from model.tables import User
from restful.data import DataUid
from restful.error import RenderUserNotExist
from restful.response import ResponseSuccess
from restful.session import data


class UserDetail(Resource):
    @data(DataUid())
    def get(self,data):
        user = QueryOneInstance(User,{'id':data['uid']})

        if not user:
            return RenderUserNotExist(data['uid'])

        return ResponseSuccess(data={
            'uid':user.id,
            'username':user.username,
            'intro':user.intro,
            'img_icon':user.img_icon,
            'img_background':user.img_background,
            'admin':user.admin,
            'role':user.role,
            'disable_until':user.disable_until,
        })
